package com.demo2do.fms.admin.dao.supplier;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.demo2do.fms.entity.reform.Reform;
import com.demo2do.fms.entity.supplier.common.Supplier;

/**
 *
 * @author Ark
 *
 */
@Dao("hibernate")
public interface ReformDao {

    /**
     * @return
     */
    @Query("SELECT COUNT(*) FROM Reform WHERE disabled = false")
    public int count();
    
    /**
     * @param originate
     * @return
     */
    @Query("SELECT COUNT(*) FROM Reform WHERE disabled = false AND originate = :originate")
    public int countByOriginate(@Variable("originate") Supplier originate);
    
    /**
     * @param recipient
     * @return
     */
    @Query("SELECT COUNT(*) FROM Reform WHERE disabled = false AND recipient = :recipient")
    public int countByRecipient(@Variable("recipient") Supplier recipient);
    
    /**
     * @param benginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Reform WHERE disabled = false ORDER BY appointTime DESC")
    public List<Reform> list(@Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
    /**
     * @param originate
     * @param benginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Reform WHERE disabled = false AND originate = :originate ORDER BY appointTime DESC")
    public List<Reform> listByOriginate(@Variable("originate") Supplier originate, @Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
    /**
     * @param recipient
     * @param benginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Reform WHERE disabled = false AND recipient = :recipient ORDER BY appointTime DESC")
    public List<Reform> listByRecipient(@Variable("recipient") Supplier recipient, @Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
}
